<& /site/header.html &>
<%perl>
   
	use YAML;
	use Data::Dumper;
	use XML::Smart;
	my $xml = new XML::Smart( 'e:/baseliner/root/harform/GBP.xml' );
	my %ret;
	my @meta;
	my %ext_map = (  combobox=>'Select', 'date-field'=>'Date', 'text-area'=>'Textarea', 'text-field'=>'Text' );
	my %kkey;
	for my $key (  $xml->{harvest_form}->order  ) {
		if( grep( /$key/, qw/combobox text-field date-field text-area/ ) ) {
			my $f = $xml->{harvest_form}->{$key}[ $kkey{$key}++ ];
			my $form = { };
			$form->{type} = $ext_map{$key};
			$form->{id} = "$f->{dbfield}";
			$form->{name} = "$f->{dbfield}";
			$form->{label} = "$f->{label}";
			$form->{size} = "$f->{maxsize}" if( $key =~ /text-field/ );
			$form->{anchor} = "80%" if(  $key =~ /text-area/ );
			# Combo Stuff
			if(  $key =~ /combobox/ ) {
				my $k = 0;
				for(  $f->{entry}->('@') ) {
					push @{ $form->{data} }, [ "id" . $k++ , "$_" ];
				}
			}
			push @meta, $form; 
		} else {
			$ret{$key} = $xml->{harvest_form}->{$key} . "";
		}
	}
	my $form = js_dumper( { xtype=> 'form', items=> [ @meta ] } );
</%perl>
<script type="text/JavaScript">
Ext.onReady(function(){
		var tb = new Ext.Toolbar({
			id: 'formtb',
			items: [ 
			'FormTitle',
			'->',
			{ xtype:'button', text: 'Submit', handler: function(){ Baseliner.formSubmit(comp.getForm())} },
			{ xtype:'button',text:'Reset' } 
			] 
		});
		var tabpanel = Ext.getCmp('main-panel');
		var comp = <% $form %>
		
		var tab = tabpanel.add({ xtype:'panel', layout: 'fit' , border: 0 , tbar: tb, items: [ comp  ] });
		tab.setTitle( "FORM" );
		tabpanel.setActiveTab(tab);
});
</script>

</body>


